# # import json
# # from datetime import datetime
# # import rsa
# # import os
# # import ast
# # from Crypto.PublicKey import RSA
# # from Crypto.Signature import PKCS1_v1_5
# # from Crypto.Hash import SHA256
# # from drf_movie_rimi import settings
# # from base64 import decodebytes, encodebytes
# # import requests
# # from base64 import encodebytes,decodebytes
# # from urllib.parse import urlencode
# #
# # url = 'https://openapi.alipay.com/gateway.do'  # 请求支付网关
# #
# # biz_content_dict = {
# #     'out_trade_no': '12312415',
# #     'total_amount': '88.88',
# #     'subject': 'iphone6s',
# #
# # }
# #
# # biz_content = biz_content_dict
# #
# #
# # timestamp = datetime.now()
# #
# # timestamp = timestamp.strftime("%Y-%m-%d %H:%M:%S")
# #
# # params = {
# #     'app_id':'2018080660974232',
# #     'method':"alipay.trade.create",
# #     'charset':'utf-8',
# #     'sign_type':'RSA2',
# #     'timestamp':timestamp,
# #     'version':'1.0',
# #     'notify_url':'http://176.122.175.246:8000/mytest/test6',
# #     'biz_content':biz_content
# # }
# #
# #
# # def sortedDictValues(adict):
# #     keys = adict.keys()
# #     sorted(keys)
# #     string = ""
# #     for i in sorted(keys):
# #         string += "{}={}&".format(i, adict[i])
# #
# #     return string[0:-1]
# #
# #
# # unsign_str = sortedDictValues(params)
# #
# # print(unsign_str)
# # x= 1
# # # def sign_str(unsigned_string):
# # #     # 开始计算签名
# # #     unsigned_string = unsigned_string.encode('utf8')
# # #     key_path = os.path.join(settings.BASE_DIR,'keys','rsa_private_key.pem')
# # #
# # #     with open(key_path) as fp:
# # #         alipay_public_key = RSA.import_key(fp.read())
# # #
# # #     signer = PKCS1_v1_5.new(alipay_public_key)
# # #     signature = signer.sign(SHA256.new(unsigned_string))
# # #     # base64 编码，转换为unicode表示并移除回车
# # #     sign = encodebytes(signature).decode("utf8").replace("\n", "")
# # #     return sign
# #
# =======
# import json
# from datetime import datetime
# import rsa
# import os
# import ast
# from Crypto.PublicKey import RSA
# from Crypto.Signature import PKCS1_v1_5
# from Crypto.Hash import SHA256
# from drf_movie_rimi import settings
# from base64 import decodebytes, encodebytes
# import requests
# from base64 import encodebytes,decodebytes
# from urllib.parse import urlencode
# from urllib.parse import quote_plus
#
# url = 'https://openapi.alipaydev.com/gateway.do'  # 请求支付网关
#
# biz_content_dict = {
#     'out_trade_no': '12312415',
#     'product_code':'FAST_INSTANT_TRADE_PAY',
#     'total_amount': 88.88,
#     'subject': 'iphone6s',
#
# }
#
# biz_content = json.dumps(biz_content_dict)
#
#
# timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#
# params = {
#     "sign_type":"RSA2",
#     "app_id":"2016091800541924",
#     "method":"alipay.trade.page.pay",
#     "charset":"utf-8",
#     "timestamp":timestamp,
#     "version":"1.0",
#     "notify_url":"http://176.122.175.246:8000/mytest/test6",
#     "biz_content":biz_content,
#
# }
#
#
# def sortedDictValues(adict):
#     keys = adict.keys()
#     sorted(keys)
#     string = ""
#     for i in sorted(keys):
#         string += "{}={}&".format(i, adict[i])
#
#     return string[0:-1]
#
# def sortedDict(adict):
#     keys = adict.keys()
#     sorted(keys)
#     tmp_dict = {}
#     for i in sorted(keys):
#         tmp_dict[i] = adict[i]
#
#     return tmp_dict
#
#
# unsign_str = sortedDictValues(params)
#
# print(unsign_str)
# x= 1
# >>>>>>> cf42d09fc87caf6b213a2b475c348fbeb44c0fdb
# # def sign_str(unsigned_string):
# #     unsigned_string = unsigned_string.encode('utf8')
# #     # 开始计算签名
# #     key_path = os.path.join(settings.BASE_DIR, 'keys', 'rsa_private_key.pem')
# #     # data1, data2 = rsa.newkeys(2048)
# #     with open(key_path, 'rb') as fp:
# #         public_key = rsa.PrivateKey.load_pkcs1(fp.read())
# #
# #     sign = rsa.encrypt(unsigned_string, public_key)
# #     return encodebytes(sign).decode("utf8").replace("\n", "")
# #
# <<<<<<< HEAD
# #
# #
# #
# # # ETcNA5ucd6M9UvtdFBlORPdIYPlVqmicdUuxRhuMtdq4B33Hsp+igxLuVmUPuTHs5wExRyJAt45m6Dx3NcqKYx7nRcSayP9ZVosFGpp/oJckGbAC176e9jtcWAY3PitYwY9Sp3LkNxVpoh1uM+HHitUBsdt+IoBDP+hwIjTOjtZjBfEhS5kOAKlfRqxLYQJX4uNrHeQhjx0b/pqbyy88OdouVbZknuThUFMNcBpw0M8I2nX+MD6b5f/K3mVRPmUGkkZbnBEjmELrAgne4rIFyN77Zhdq55k64kavR4/os2wIDAQAB"
# # res = sign_str(unsign_str)
# # # x = res.decode('')
# # params.update({'sign': res})
# #
# # res = requests.get(url, params=params)
# # content = res.content.decode('utf8')
# # print(content)
# #
# # data1, data2 = rsa.newkeys(2048)
# #
# # x = 1
#
# from rest_framework.views import APIView
# from django.contrib.auth import get_user_model
# from rest_framework.response import Response
# from django.http import HttpResponse
# # from movie_orders.pay_test2 import AliPay
# from django.views.decorators.csrf import csrf_exempt
#
# User = get_user_model()
#
#
# @csrf_exempt
# def pay_test(request):
#     data = request.POST.dict() or request.GET.dict()
#     alipay = AliPay(
#         debug=True,  # 默认False,
#     )
#     sign = data.pop('sign')
#     res = alipay.verify(data, sign)
#     return HttpResponse('asdf')
# =======
# #     signer = PKCS1_v1_5.new(alipay_public_key)
# #     signature = signer.sign(SHA256.new(unsigned_string))
# #     # base64 编码，转换为unicode表示并移除回车
# #     sign = encodebytes(signature).decode("utf8").replace("\n", "")
# #     return sign
#
# def sign_str(unsigned_string):
#     unsigned_string = unsigned_string.encode('utf8')
#     # 开始计算签名
#     key_path = os.path.join(settings.BASE_DIR, 'keys', 'rsa_private_key.pem')
#     # data1, data2 = rsa.newkeys(2048)
#     with open(key_path, 'rb') as fp:
#         public_key = rsa.PrivateKey.load_pkcs1(fp.read())
#
#     sign = rsa.sign(unsigned_string, public_key,"SHA-1")
#     return encodebytes(sign).decode("utf8").replace("\n","")
#
#
#
#
# # ETcNA5ucd6M9UvtdFBlORPdIYPlVqmicdUuxRhuMtdq4B33Hsp+igxLuVmUPuTHs5wExRyJAt45m6Dx3NcqKYx7nRcSayP9ZVosFGpp/oJckGbAC176e9jtcWAY3PitYwY9Sp3LkNxVpoh1uM+HHitUBsdt+IoBDP+hwIjTOjtZjBfEhS5kOAKlfRqxLYQJX4uNrHeQhjx0b/pqbyy88OdouVbZknuThUFMNcBpw0M8I2nX+MD6b5f/K3mVRPmUGkkZbnBEjmELrAgne4rIFyN77Zhdq55k64kavR4/os2wIDAQAB"
# res = sign_str(unsign_str)
# # x = res.decode('')
# params.update({'sign': res})
#
# params_quote = {}
# for i in sortedDict(params):
#     params_quote[i] = quote_plus(params[i])
#
#
#
# res = requests.get(url, params=sortedDict(params))
# x = res.url
# content = res.content.decode('utf8')
# print(content)
#
# data1, data2 = rsa.newkeys(2048)
#
# x = 1
# >>>>>>> cf42d09fc87caf6b213a2b475c348fbeb44c0fdb
